package com.back.service.context;


import com.back.service.PayService;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@Component
public class PayContext {

    @Resource
    private List<PayService> payServices;


    private HashMap<Integer, PayService> payServiceMap = new HashMap<>();

    @PostConstruct
    public void payInit() {
        payServices.forEach(payService -> payServiceMap.put(payService.getType(), payService));
    }


    public String getPayService(Integer type) {
        PayService payService = payServiceMap.get(type);
        String pay = payService.pay();
        return pay;
    }

    public String query(Integer type) {
        PayService payService = payServiceMap.get(type);
        String pay = payService.query();
        return pay;
    }
}
